package com.atguigu.yygh.user.controller;

import com.atguigu.yygh.common.model.user.UserInfo;
import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.common.vo.user.UserInfoQueryVo;
import com.atguigu.yygh.user.service.UserInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Resource
    private UserInfoService userInfoService;

    //显示用户列表(条件查询带分页)
    @GetMapping("{page}/{limit}")
    public Result<IPage<UserInfo>> list(@PathVariable Long page,
                                        @PathVariable Long limit,
                                        UserInfoQueryVo userInfoQueryVo) {

        Page<UserInfo> pageParam = new Page<>(page, limit);

        IPage<UserInfo> pageModel =
                userInfoService.selectPage(pageParam, userInfoQueryVo);

        return Result.ok(pageModel);
    }

    //用户锁定功能
    @ApiOperation(value = "用户锁定")
    @GetMapping("lock/{userId}/{status}")
    public Result<Void> lock(@PathVariable Long userId,
                             @PathVariable Integer status) {

        userInfoService.lock(userId, status);
        return Result.ok();
    }

    @ApiOperation(value = "用户详情")
    @GetMapping("show/{userId}")
    public Result<Map<String, Object>> show(@PathVariable Long userId) {
        Map<String, Object> userMap = userInfoService.show(userId);
        return Result.ok(userMap);
    }

    @ApiOperation(value = "用户认证审批")
    @GetMapping("approval/{userId}/{authStatus}")
    public Result<Void> approval(@PathVariable Long userId,
                                 @PathVariable Integer authStatus){

        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }


}
